﻿using ERP.ERPSystem.ProductionSystem;
using ERP.ERPSystem.ProductionSystem.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace ERP.Web.Controllers.ProductionSystem
{
    /// <summary>
    /// 客户管理控制器
    /// </summary>
    [Route("Customer")]
    public class CustomerController : Controller
    {
        private readonly ICustomerServices _customerServices;

        public CustomerController(ICustomerServices customerServices)
        {
            _customerServices = customerServices;
        }

        /// <summary>
        /// 返回客户管理的主视图页面
        /// </summary>
        [HttpGet("Index")]
        public IActionResult CustomerQuery()
        {
            return View();
        }

        /// <summary>
        /// 获取客户分页列表数据
        /// </summary>
        [HttpGet("api/list")]
        public Task<PagedResultDto<CustomerDto>> GetListAsync([FromQuery] GetCustomerInputDto input)
        {
            return _customerServices.GetListAsync(input);
        }

        /// <summary>
        /// 创建新客户
        /// </summary>
        [HttpPost("api/create")]
        public Task<CustomerDto> CreateAsync([FromBody] CreateUpdateCustomerDto input)
        {
            return _customerServices.CreateAsync(input);
        }

        /// <summary>
        /// 更新客户信息
        /// </summary>
        [HttpPut("api/update/{id}")]
        public Task<CustomerDto> UpdateAsync(int id, [FromBody] CreateUpdateCustomerDto input)
        {
            return _customerServices.UpdateAsync(id, input);
        }

        /// <summary>
        /// 删除单个客户
        /// </summary>
        [HttpDelete("api/delete/{id}")]
        public Task DeleteAsync(int id)
        {
            return _customerServices.DeleteAsync(id);
        }

        /// <summary>
        /// 批量删除客户
        /// </summary>
        [HttpPost("api/batch-delete")]
        public Task DeleteManyAsync([FromBody] IEnumerable<int> ids)
        {
            return _customerServices.DeleteManyAsync(ids);
        }
    }
}
